package com.googlecode.likesql.utils;

/**
 * This class is to manipulate arrays.
 * 
 * @author Johny Huang
 * @since 0.1
 *
 */
public final class ArrayUtils {

	/**
	 * Convert to object arrays.
	 * 
	 * @param chars
	 * @return
	 */
	public static Double[] toObjectArray(double[] doubles){
		if(doubles==null){
			return null;
		}
		Double[] objArray=new Double[doubles.length];
		for(int i=0;i<objArray.length;i++){
			objArray[i]=new Double(doubles[i]);
		}
		return objArray;
	}
	
	/**
	 * Convert to object arrays.
	 * 
	 * @param chars
	 * @return
	 */
	public static Integer[] toObjectArray(int[] ints){
		if(ints==null){
			return null;
		}
		Integer[] objArray=new Integer[ints.length];
		for(int i=0;i<objArray.length;i++){
			objArray[i]=new Integer(ints[i]);
		}
		return objArray;
	}
	
	/**
	 * Convert to object arrays.
	 * 
	 * @param chars
	 * @return
	 */
	public static Long[] toObjectArray(long[] longs){
		if(longs==null){
			return null;
		}
		Long[] objArray=new Long[longs.length];
		for(int i=0;i<objArray.length;i++){
			objArray[i]=new Long(longs[i]);
		}
		return objArray;
	}
	
	/**
	 * Convert to object arrays.
	 * 
	 * @param chars
	 * @return
	 */
	public static Float[] toObjectArray(float[] floats){
		if(floats==null){
			return null;
		}
		Float[] objArray=new Float[floats.length];
		for(int i=0;i<objArray.length;i++){
			objArray[i]=new Float(floats[i]);
		}
		return objArray;
	}
	
	/**
	 * Convert to object arrays.
	 * 
	 * @param chars
	 * @return
	 */
	public static Character[] toObjectArray(char[] chars){
		if(chars==null){
			return null;
		}
		Character[] objArray=new Character[chars.length];
		for(int i=0;i<objArray.length;i++){
			objArray[i]=new Character(chars[i]);
		}
		return objArray;
	}
	
	/**
	 * Returns true if values is null or its length equals 0.
	 * 
	 * @param values
	 * @return
	 */
	public static boolean isNotEmpty(Object[] values){
		return values==null || values.length>0;
	}
	
	private ArrayUtils(){
		
	}
}
